package com.wz.wzbubbleai.database;

import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by wangbin on 18-1-16.
 */



public class ChatDataBaseHelper extends SQLiteOpenHelper {

    private static final String  DB_NAME = "CHATAI.DB";//数据库名称
    private static final int DB_VERSION = 1;//数据库版本号

    private Context mContext;


    public ChatDataBaseHelper(Context context){
        super(context,DB_NAME,null,DB_VERSION);
    }
    //version  数据库版本号 context 上下文 name数据库名字
    public ChatDataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DB_NAME, factory, DB_VERSION);
    }

    public ChatDataBaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
        super(context, DB_NAME, factory, DB_VERSION, errorHandler);
    }

    /**
     * 创建数据库
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        //获取创建表格的SQL
        String netNewsSQL = NewChatTable.getCreatNetNewsSQL();
        db.execSQL(netNewsSQL);
    }

    /**
     * 创建数据库时不会执行，增大版本号升级时才会执行到
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table "+ NewChatTable.TBL_NAME);
        onCreate(db);
    }
}